package com.wangwen.wechatmp.pay;

import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.xml.bind.annotation.XmlAccessorType;

/**
 * @Author: wangwei
 * @Date: 2019/12/2 14:08
 */

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@XStreamAlias("xml")
@XmlAccessorType
public class FacePayResult extends BaseWxPayResult {

    private static final long serialVersionUID = 3381324564266118986L;


    /**
     * <pre>
     * 是否关注公众账号.
     * 仅在公众账号类型支付有效，取值范围：Y或N;Y-关注;N-未关注
     * </pre>
     */
    @XStreamAlias("is_subscribe")
    private String isSubscribe;
    @XStreamAlias("custom_error_msg")
    private String customErrorMsg;

    @XStreamAlias("openid")
    private String openid;


    @XStreamAlias("trade_type")
    private String tradeType;


    @XStreamAlias("bank_type")
    private String bankType;


    @XStreamAlias("total_fee")
    private Integer totalFee;



    @XStreamAlias("fee_type")
    private String feeType;


    @XStreamAlias("transaction_id")
    private String transactionId;

    @XStreamAlias("out_trade_no")
    private String outTradeNo;

    @XStreamAlias("attach")
    private String attach;

    @XStreamAlias("time_end")
    private String timeEnd;

    @XStreamAlias("sub_openid")
    private String subOpenid;

    @XStreamAlias("cash_fee")
    private String cashFee;

    @XStreamAlias("cash_fee_type")
    private String cashFeeType;

    @XStreamAlias("promotion_detail")
    private String promotionDetail;

    /**
     * 重写  fromXML  解决 com.thoughtworks.xstream.security.ForbiddenClassException  问题
     * @param xmlString
     * @param clz
     * @param <T>
     * @return
     */
    public static <T extends BaseWxPayResult> T fromXML(String xmlString, Class<T> clz) {
//        XStream xstream = XStreamInitializer.getInstance();
        XStream xstream = new XStream();
        xstream.processAnnotations(clz);
        //解决 com.thoughtworks.xstream.security.ForbiddenClassException
        XStream.setupDefaultSecurity(xstream);
        Class<?>[] classes = new Class[] { FacePayResult.class};
        xstream.allowTypes(classes);
        T result = (T) xstream.fromXML(xmlString);
        result.setXmlString(xmlString);
        return result;
    }
}
